package cn.tedu.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;



//                                          更新Demo
public class JDBCDemo2 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        /*Scanner scan=new Scanner(System.in);
        System.out.println("请输入你的用户名！");
        String username=scan.nextLine();
        System.out.println("请输入要修改的密码~！");
        String pass=scan.nextLine();
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                    "root",
                "root"
                );
        Statement statement = connection.createStatement();
        String sql="update userinfo set password="+pass+" where  username='"+username+"'";
        int i=statement.executeUpdate(sql);
        System.out.println(i+"条表记录发生变化！");
        connection.close();*/

        Scanner scan=new Scanner(System.in);
        System.out.println("请输入你的用户名！");
        String username=scan.nextLine();
        System.out.println("请输入要修改的密码~！");
        String pass=scan.nextLine();
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                    "root",
                "root"
        );
        Statement statement = connection.createStatement();
        String sql="update userinfo set password='"+pass+"' where  username='"+username+"'";
        int i = statement.executeUpdate(sql);
        if (i>0){
            System.out.println("你修改的数据为"+i+"条");
        }else{
            System.out.println("用户名错误！修改失败");
        }
        connection.close();

    }
}
